package net.linku.feign;

import net.linku.exception.config.FeignConfig;
import net.linku.feign.response.JwtToken;
import net.linku.feign.fallback.Oauth2ClientFallback;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * @ClassName Oauth2FeignClient
 * @Description: Feign客户端，用于远程调用授权服务器以获取Token
 * @Author SilenceTian
 * @Date 2023/12/21
 * @Version V1.0
 **/

@FeignClient(value = "authorization-server", configuration = FeignConfig.class, fallback = Oauth2ClientFallback.class)
public interface Oauth2FeignClient {

    /**
     * 获取OAuth2 Token
     *
     * @param username   用户名
     * @param password   密码
     * @param grantType  授权类型
     * @param loginType  登录类型
     * @param basicToken 基础token
     * @param tenantId   租户ID
     * @return JWT Token响应
     */
    @PostMapping("/oauth/token")
    ResponseEntity<JwtToken> getToken(
            @RequestParam("username") String username,
            @RequestParam("password") String password,
            @RequestParam("grant_type") String grantType,
            @RequestParam("login_type") String loginType,
            @RequestHeader("Authorization") String basicToken,
            @RequestHeader("X-Tenant-ID") Long tenantId
    );
}
